/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) CryptoInit.java 2018-08-13 15:28
 */

package cn.jh.common.core.crypto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.Security;


/**
 * 检测Java版本，自动选择是否开启 JCE Unlimited.
 *
 * @author Fuchun
 * @since 1.0
 */
class CryptoInit {

    private static final Logger LOGGER = LoggerFactory.getLogger(CryptoInit.class);

    static {
        try {
            // 自动开启支持密钥无限制，JAVA 1.8.0_151 之后的版本可用，之前的版本需要到官网下载 JCE Unlimited 补丁文件。
            // Java9之后，默认开启 crypto.policy=unlimited，不需要进行任何设置
            Security.setProperty("crypto.policy", "unlimited");
            LOGGER.info("Current Java security `crypto.policy` set to `unlimited`.");
        } catch (Exception ex) {
            LOGGER.warn("Current Java version is not support `crypto.policy` to `unlimited`. " +
                    "Minimum version must be `1.8.0_151`. Otherwise you can download JCE Unlimited package.");
        }
    }

    private CryptoInit() {
    }
}
